package main

import (
	"fmt"
	"net"
	"os"
)
import "vad/src"

var outfile *os.File

func main() {
	fmt.Println("vad 测试服务")

	outfile, _ = os.Create("sample/rec.txt")
	defer outfile.Close()

	addr, _ := net.ResolveUDPAddr("udp", "0.0.0.0:1235")
	conn, _ := net.ListenUDP("udp", addr)
	defer conn.Close()
	go UdpProcess(conn)

	//src.VadTest("16k_1.pcm",16000,20)
	//src.VadTest("16k_57test.pcm")
	//src.VadTest("16k_test.pcm")
	//src.VadTest("16k_nopause.pcm")

	select {}
}

func UdpProcess(conn *net.UDPConn) {
	for {
		bytes := make([]byte, 16000)
		_, _, _ = conn.ReadFromUDP(bytes)
		src.VadCheck(bytes, 16000, 20)
		outfile.Write(bytes)
	}
}
